package com.tencent.qf.user.controller;

import com.tencent.qf.common.aspect.annotation.ApiLog;
import com.tencent.qf.common.aspect.annotation.Signature;
import com.tencent.qf.common.pojo.HttpResult;
import com.tencent.qf.user.dal.UserRelationRecord;
import com.tencent.qf.user.dal.UserTutorRelation;
import com.tencent.qf.user.dto.UserBasicInfo;
import com.tencent.qf.user.dto.UserInfoDetail;
import com.tencent.qf.user.dto.request.*;
import com.tencent.qf.user.dto.response.*;
import com.tencent.qf.user.dto.request.BatchUserInfoDTO;
import com.tencent.qf.user.dto.request.TeamUserInfoRequest;
import com.tencent.qf.user.dto.request.UserInfoDTO;
import com.tencent.qf.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@Api(value = "用户", tags = "用户管理", protocols = "http")
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Signature
    @ApiLog("用户分层-用户下单情况")
    @ApiOperation("用户分层-用户下单情况")
    @PostMapping("/userPaymentInfo")
    public HttpResult<UserPaymentCountDTO> userPaymentInfo(@RequestBody @Valid UserInfoDTO userInfoDTO) {
        return userService.userPaymentInfo(userInfoDTO);
    }


    @Signature
    @ApiLog("用户分层-用户下单情况(包含京享礼金)")
    @ApiOperation("用户分层-用户下单情况(包含京享礼金)")
    @PostMapping("/userPaymentInfo/jdGiftCoupon")
    public HttpResult<UserPaymentCountDTO> userPaymentInfoIncludeJdGiftCoupon(@RequestBody @Valid UserPaymentInfoIncludeJdGiftCouponReq request) {
        return HttpResult.success(userService.userPaymentInfoIncludeJdGiftCoupon(request));
    }

    @Signature
    @ApiLog("用户分层-用户下单情况V2")
    @ApiOperation("用户分层-用户下单情况V2")
    @PostMapping("/userPaymentInfoV2")
    public HttpResult<UserPaymentCountDTO> userPaymentInfoV2(@RequestBody @Valid UserInfoDTO userInfoDTO) {
        return HttpResult.success(userService.userPaymentInfoV2(userInfoDTO));
    }

    @Signature
    @ApiLog("批量获取用户分层信息")
    @ApiOperation("批量获取用户分层信息")
    @PostMapping("/userPaymentInfoBatch")
    public HttpResult<List<UserPaymentCountDTO>> userPaymentInfo(@RequestBody @Valid BatchUserInfoDTO batchUserInfoDTO) {
        return userService.batchUserPaymentInfo(batchUserInfoDTO.getUserInfoDTOs());
    }

    @Signature
    @ApiLog("批量获取用户分层信息V2")
    @ApiOperation("批量获取用户分层信息V2")
    @PostMapping("/userPaymentInfoBatchV2")
    public HttpResult<List<UserPaymentCountDTO>> userPaymentInfoV2(@RequestBody @Valid BatchUserInfoDTO batchUserInfoDTO) {
        return userService.batchUserPaymentInfoV2(batchUserInfoDTO.getUserInfoDTOs());
    }

    @Signature
    @ApiLog("查询特定单品A单数量")
    @ApiOperation("查询特定单品A单数量")
    @PostMapping("/queryAOrderNumBySkuId")
    public HttpResult<AOrderNumInfo> queryAOrderNumBySkuId(@RequestBody @Valid QueryAOrderNumBySkuIdRequest request) {
        return userService.queryAOrderNumBySkuId(request);
    }

    @Signature
    @ApiLog("查询全场A单数量")
    @ApiOperation("查询全场A单数量")
    @PostMapping("/queryAOrderNumAll")
    public HttpResult<AOrderNumInfo> queryAOrderNumAll(@RequestBody @Valid QueryAOrderNumAllRequest request) {
        return userService.queryAOrderNumAll(request);
    }

    @Signature
    @ApiLog("查询全场A单数量批量接口")
    @ApiOperation("查询全场A单数量批量接口")
    @PostMapping("/queryAOrderNumAllBatch")
    public HttpResult<List<AOrderNumInfo>> queryAOrderNumAllBatch(@RequestBody @Valid QueryAOrderNumAllRequest request) {
        return userService.queryAOrderNumAllBatch(request);
    }


    @Signature
    @ApiLog("批量查询用户绑定关系")
    @ApiOperation("批量查询用户绑定关系")
    @PostMapping("/relation/record/batch")
    public HttpResult<List<UserRelationRecord>> userRelationRecordBatch(@RequestBody UserRelationRecordBatchRequest request) {
        return userService.userRelationRecordBatch(request);
    }

    @Signature
    @ApiLog("通过uid、unionId查询用户信息")
    @ApiOperation("通过uid、unionId查询用户信息")
    @PostMapping("/userInfo/byUidUnionId")
    public HttpResult<UserInfoDetail> userInfoByUidUnionId(@RequestBody UserInfoByUidUnionIdRequest request) {
        return userService.userInfoByUidUnionId(request);
    }

    @Signature
    @ApiLog("批量查询用户基础信息")
    @ApiOperation("批量查询用户基础信息")
    @PostMapping("/getUserInfoByUid/batch")
    public HttpResult<List<UserBasicInfo>> userBasicInfoBatch(@RequestBody UserBasicInfoBatchRequest request) {
        return userService.getUserBasicInfos(request);
    }

    @Signature
    @ApiLog("获取用户是否修改头像昵称")
    @ApiOperation("获取用户是否修改头像昵称")
    @PostMapping("/isEditNickNameOrHeadUrl")
    public HttpResult<IsEditNickNameOrHeadUrlResponse> isEditNickNameOrHeadUrl(@RequestBody @Valid IsEditNickNameOrHeadUrlRequest request) {
        return userService.isEditNickNameOrHeadUrl(request.getUid());
    }

    @ApiLog("团长uid查询接口")
    @ApiOperation("团长uid查询接口")
    @PostMapping("/iris/team/userInfo")
    public HttpResult<List<IrisUserInfoDTO>> teamUserInfo(@RequestBody TeamUserInfoRequest request) {
        return userService.teamUserInfo(request);
    }

    @ApiLog("免单抽奖查询奖池信息")
    @ApiOperation("免单抽奖查询奖池信息")
    @PostMapping("/freeLottery/awardPoolInfo")
    public HttpResult<LotteryAwardInfo> awardPoolInfo(@RequestBody QueryLotteryAwardInfoRequest request) {
        return userService.getAwardPoolInfo(request);
    }


    @Signature
    @ApiLog("对比用户分层数据数据")
    @ApiOperation("对比用户分层数据数据")
    @PostMapping("/compareUserPaymentInfo")
    public HttpResult<List<String>> compareUserPaymentInfo(@RequestBody CompareUserPaymentRequest request){
        return userService.compareUserPaymentInfo(request.getMinPage(),request.getMaxPage(), request.getSize());
    }

    @Signature
    @ApiLog("批量获取订单详情")
    @ApiOperation("批量获取订单详情")
    @PostMapping("/orderInfoById/batch")
    public HttpResult<List<OrderInfo>> orderInfos(@RequestBody BatchOrderInfoRequest request) {
        return userService.getOrderInfos(request);
    }

    @Signature
    @ApiLog("批量查询用户绑定导师关系")
    @ApiOperation("批量查询用户绑定导师关系")
    @PostMapping("/relation/tutor/batch")
    public HttpResult<List<UserTutorRelation>> userRelationTutorBatch(@RequestBody UserRelationTutorBatchRequest request) {
        return userService.userRelationTutorBatch(request);
    }

    @Signature
    @ApiLog("查询用户区域信息、上级uid、导师uid")
    @ApiOperation("查询用户区域信息、上级uid、导师uid")
    @PostMapping("/userInfo/forGoldDetail")
    public HttpResult<UserInfoForGoldDetail> userInfoForGoldDetail(@RequestBody @Valid UserInfoForGoldDetailRequest request) {
        return userService.userInfoForGoldDetail(request);
    }

    @Signature
    @ApiLog("批量获取订单详情")
    @ApiOperation("批量获取订单详情")
    @PostMapping("/orderInfoByUid/batch")
    public HttpResult<List<OrderInfoByUid>> orderInfosByUid(@RequestBody OrderInfoByUidRequest request) {
        return userService.getOrderInfosByUid(request);
    }

    @Signature
    @ApiLog("批量查询用户上级信息")
    @ApiOperation("批量查询用户上级信息")
    @PostMapping("/parentInfo/batch")
    public HttpResult<List<ParentInfo>> userParentInfoBatch(@RequestBody ParentInfoBatchRequest request) {
        return userService.userParentInfoBatch(request);
    }

    @Signature
    @ApiLog("查询用户有效订单")
    @ApiOperation("查询用户有效订单")
    @PostMapping("/queryEfficientOrderNum")
    public HttpResult<List<EfficientOrderNumInfo>> queryEfficientOrderNum(@RequestBody EfficientOrderNumRequest request) {
        return userService.queryEfficientOrderNum(request);
    }

    @Signature
    @ApiLog("查询用户有效分销单数")
    @ApiOperation("查询用户有效分销单数")
    @PostMapping("/queryEfficientSplitOrder")
    public HttpResult<List<EfficientOrderNumInfo>> queryEfficientSplitOrder(@RequestBody EfficientOrderNumRequest request) {
        return userService.queryEfficientSplitOrder(request);
    }

    @Signature
    @ApiLog("查询用户升级时间")
    @ApiOperation("查询用户升级时间")
    @PostMapping("/upgradeTime")
    public HttpResult<UpgradeTimeInfo> upgradeTime(@RequestBody UpgradeTimeRequest request) {
        return userService.upgradeTime(request);
    }

    @Signature
    @ApiLog("根据分销单号批量获取订单")
    @ApiOperation("根据分销单号批量获取订单")
    @PostMapping("/orderInfosByPlainOrderId")
    public HttpResult<List<OrderInfo>> orderInfosByPlainOrderId(@RequestBody OrderInfoByPlainOrderIdRequest request) {
        return userService.orderInfosByPlainOrderId(request);
    }

    @Signature
    @ApiLog("用户标签")
    @ApiOperation("用户标签")
    @PostMapping("/tags")
    public HttpResult<List<UserTagInfo>> orderInfosByUid(@RequestBody UserTagRequest userTagRequest) {
        return HttpResult.success(userService.userTags(userTagRequest.getUid(),userTagRequest.getSaasId()));
    }

}
